<template>
	<view>
		<titleBar class='background-color: red' :titleText='"逛逛"' :back='false' :pageForm='"setting"'></titleBar>
		<view class="index-content" style="background: white">
			<view class="index-coupon has-bg-white has-pd-10">
				<view class="goods-list" v-if="guangguang.length > 0&&showCopywriting" style="padding-top: 30px">
					<gg-loop v-bind:key='index' v-for="(h,index) in guangguang" :copy_content="h.copy_content" :total="h.dummy_click_statistics"
					 :content="h.show_content" :images="h.itempic" :showTime="h.show_time" :to="h.itemid"></gg-loop>
				</view>
			</view>
			<!-- 加载更多提示 -->
			<view class="s-col is-col-24" v-if="guangguang.length > 0">
				<load-more :loadingType="loadingType" :contentText="contentText"></load-more>
			</view>
		</view>
	</view>


</template>

<script>
	import titleBar from '@/components/customize/titlebar.vue'
	export default {
		components: {
			titleBar
		},
		name: "guang",
		data() {
			return {
				contentText: {
					contentdown: "上拉显示更多",
					contentrefresh: "正在加载...",
					contentnomore: "没有更多数据了"
				},
				loadingType: 0,
				scrollTop: false,
				showCopywriting: true,
				scrollLeft: 0,
				res: [],
				guangguang: [],
				guangguangLoad: {
					loading: false,
					finished: false,
					total: 1,
				},
				min_id: 1,
			}
		},
		onLoad: function(e) {
			uni.showLoading({
				title: '加载中...'
			});
			this.getCopywriting(1);
		},
		onPageScroll: function(e) {
			this.scrollTop = e.scrollTop > 200;
		},
		onReachBottom: function() {
			this.copywritingOnLoad();
		},
		methods: {
			topScrollTap: function() {
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 300
				});
			},
			copywritingOnLoad() {
				this.getCopywriting(this.copywritingLoad.total += 1);
			},
			getCopywriting(page) { //获取精选商品数据
				this.showCopywriting = true;
				this.loadingType = 1;
				this.$u.api.selectedItems({back:20,min_id:this.min_id}).then(res => {
					this.loadingType = 0;
					if (res.code === 1) {
						if (page === 1) {
							this.guangguang = [];
						}
						this.min_id = res.min_id;
						for (let i = 0; i < res.data.length; i++) {
							res.data[i].show_content = res.data[i].show_content
								.replace(/&lt;/g, "<")
								.replace(/&gt;/g, ">")
								.replace(/&amp;/g, "&")
								.replace(/&quot;/g, '"')
								.replace(/&apos;/g, "'");
							res.data[i].copy_content = res.data[i].copy_content
								.replace(/&lt;/g, "<")
								.replace(/&gt;/g, ">")
								.replace(/&amp;/g, "&")
								.replace(/&quot;/g, '"')
								.replace(/&apos;/g, "'");
							res.data[i].copy_content = res.data[i].copy_content
								.replace(/<br>/g, "\n");
							this.guangguang.push(res.data[i]);
						}
						this.guangguangLoad.loading = false;
					} else {
						this.loadingType = 2;
						this.guangguangLoad.loading = false;
						this.guangguangLoad.finished = true;
					}
					uni.hideLoading();
					uni.stopPullDownRefresh(); // 停止刷新
				});
			}
		}
	}
</script>

<style>
	page {
		background: #FFFFFF;
	}

	/deep/ .fixedBox {
		background-color: red !important;
	}
	
	/deep/ .pageTitle{
		color:#ffffff !important;
	}
</style>
